package com.autonavi.abs.generator.common.enumeration;

/**
 * @author tianquan.ld
 * @version V1.0
 * <p>Description: Java数据类型 db数据类型映射</p>
 * @date 2020-08-10 17:25
 */
public enum DataTypeEnum {

    CHAR("CHAR", "String"),
    VARCHAR("VARCHAR", "String"),
    TINYTEXT("TINYTEXT", "String"),
    MEDIUMTEXT("MEDIUMTEXT", "String"),
    TEXT("TEXT", "String"),
    LONGTEXT("LONGTEXT", "String"),

    BIT("BIT", "Integer"),
    TINYINT("TINYINT", "Integer"),
    TINYINT_UNSIGNED("TINYINT UNSIGNED", "Integer"),
    TINYINT_SIGNED("TINYINT SIGNED", "Integer"),
    SMALLINT("SMALLINT", "Integer"),
    SMALLINT_UNSIGNED("SMALLINT UNSIGNED", "Integer"),
    SMALLINT_SIGNED("SMALLINT SIGNED", "Integer"),
    MEDIUMINT("MEDIUMINT", "Integer"),
    MEDIUMINT_UNSIGNED("MEDIUMINT UNSIGNED", "Integer"),
    MEDIUMINT_SIGNED("MEDIUMINT SIGNED", "Integer"),
    INT("INT", "Integer"),
    INT_UNSIGNED("INT UNSIGNED", "Integer"),
    INT_SIGNED("INT SIGNED", "Integer"),
    INTEGER("INTEGER", "Integer"),
    BIGINT("BIGINT", "Long"),
    BIGINT_UNSIGNED("BIGINT UNSIGNED", "Long"),
    BIGINT_SIGNED("BIGINT SIGNED", "Long"),

    DATE("DATE", "java.util.Date"),
    TIME("TIME", "java.util.Date"),
    YEAR("YEAR", "java.util.Date"),
    DATETIME("DATETIME", "java.util.Date"),
    TIMESTAMP("TIMESTAMP", "java.util.Date"),

    DECIMAL("DECIMAL", "java.math.BigDecimal"),
    ;

    public String jdbcType;
    public String javaType;

    DataTypeEnum(String jdbcType, String javaType) {
        this.jdbcType = jdbcType;
        this.javaType = javaType;
    }

    public static String getJavaType(String jdbcType) {
        for (DataTypeEnum item : DataTypeEnum.values()) {
            if (item.jdbcType.equals(jdbcType)) {
                return item.javaType;
            }
        }
        return null;
    }

}
